package com.qidianit.mes.pro.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.mes.common.Result;
import com.qidianit.mes.pojo.pro.ProductionOrder;
import com.qidianit.mes.pro.mapper.ProductionOrderMapper;
import com.qidianit.mes.pro.service.ProductionOrderService;
import com.qidianit.mes.vo.ProductionOrderPageVo;
import com.qidianit.mes.vo.ProductionOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Package Path: com.qidianit.mes.pro.service.impl
 * Author: Alhz
 * Description:
 * Date: 2025/9/21 18:32
 */
@Service
public class ProductionOrderServiceImpl implements ProductionOrderService {
    @Autowired
    private ProductionOrderMapper productionOrderMapper;

    /**
     * 分页查询
     * @param productionOrderPageVo
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public Result selectAllOrders(ProductionOrderPageVo productionOrderPageVo, int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<ProductionOrderVo> productionOrderVoList = productionOrderMapper.selectAllOrders(productionOrderPageVo);
        PageInfo<ProductionOrderVo> pageInfo = new PageInfo<>(productionOrderVoList);

        return Result.success(pageInfo);
    }

    /**
     * 新增生产工单
     * @param productionOrder
     * @return
     */
    @Override
    public Result addProductionOrder(ProductionOrder productionOrder) {
        return Result.success(productionOrderMapper.addProductionOrder(productionOrder));
    }

    /**
     * 更新生产工单
     * @param productionOrder
     * @return
     */
    @Override
    public Result updateProductionOrder(ProductionOrder productionOrder) {
        return Result.success(productionOrderMapper.updateProductionOrder(productionOrder));
    }

    /**
     * 根据id获取生产工单
     * @param id
     * @return
     */
    @Override
    public Result getProductionOrderById(Long id) {
        return Result.success(productionOrderMapper.getProductionOrderById(id));
    }

    @Override
    public Result deleteProductionOrderById(Long id) {
        return Result.success(productionOrderMapper.deleteByProductionOrderId(id));
    }

    @Override
    public Result updateProductionOrderStatus(Long id, Integer status) {
        return Result.success(productionOrderMapper.updateProductionOrderStatus(id, status));
    }








}
